import React from "react";
import ReactDOM from "react-dom";
// import './index.css';
import App from "./App.jsx";
// import reportWebVitals from './reportWebVitals';
import { createStore } from "redux";

import {add, del} from './actions'

function reducer(state = { name: "zs", age: 22, count: 10 }, action) {
  switch (action.type) {
    case "INCREASE":
      return { ...state, count: state.count + action.count };
    case "DECREASE":
      return { ...state, count: state.count - action.count };
    default:
      return state;
  }
}

const store = createStore(reducer);

store.subscribe(() => {console.log(store.getState())});

ReactDOM.render(
  <App
    value={store.getState()}
    onIncrement={(count = 1) => { store.dispatch(add(count))}}
    onDecrement={(count = 1) => store.dispatch(del(count))}
  />,
  document.getElementById("root")
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
// reportWebVitals();
